<?php

namespace app\api\controller\v1;

use app\common\controller\BaseController;
use app\common\validate\AddressValidate;
use app\common\model\Address as AddressModel;

class Address extends BaseController
{
    // 添加收货地址
    public function create()
    {
        // 验证
        (new AddressValidate())->goCheck('create');
        (new AddressModel())->createAddress();
        return self::showResCodeWithOutData('添加成功');
    }

    // 获取地址列表
    public function getAddressList()
    {
        $list = (new AddressModel())->addressList();
        return self::showResCode('获取成功',compact('list'));
    }

    // 获取详情
    public function getAddressDetail()
    {
        // 验证
        (new AddressValidate())->goCheck('addressDetail');
        $detail = (new AddressModel())->addressDetail();
        return self::showResCode('获取成功',compact('detail'));
    }

    // 编辑收货地址
    public function update()
    {
        // 验证
        (new AddressValidate())->goCheck('update');
        (new AddressModel())->updateAddress();
        return self::showResCodeWithOutData('修改成功');
    }
}
